package com.file.tool.utils.excel.stupdit1t;

import com.github.stupdit1t.excel.common.PoiWorkbookType;
import com.github.stupdit1t.excel.core.ExcelHelper;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author wanglulu
 * @description: stupdit1t 导出excel操作
 * @date 2023/01/30 14:58
 * <p>
 * https://github.com/stupdit1t/poi-excel
 */
public class ExcelStupditUtil {

    /**
     * 无模板 自定义属性 导出excel
     *
     * @param data     数据 [{"requestUri":“”, "requestMethod":“”, "ip":“”, "errorSimpleInfo":“”, "createDate":“”, "creatorName":“”}]
     * @param headers  表头列名称 ["请求地址", "请求方式", "IP地址", "简要信息", "异常时间", "创建人"]
     * @param fields   列表字段  ["requestUri", "requestMethod", "ip", "errorSimpleInfo", "createDate", "creatorName"]
     * @param fileName 文件名称
     * @param response
     * @throws Exception
     */
    public static void export(List<?> data, String[] headers, String[] fields, String fileName, HttpServletResponse response) throws Exception {
        ExcelHelper.opsExport(PoiWorkbookType.XLSX).opsSheet(data).opsHeader().simple().texts(headers).done().opsColumn().fields(fields).done().done().export(response, fileName + System.currentTimeMillis() + ".xlsx");
    }

}
